#!/usr/bin/env pypy

import unittest, os

from datetime import datetime

import playlist_module

from track import Track
from settings import settings

class TestTrack(unittest.TestCase):

	@classmethod
	def setUpClass(cls):
		TestTrack.modified = datetime.today()

		TestTrack.files = {ext: os.path.join(u"data", u"test.{ext}".format(ext = ext)) for ext in ("ogg", "m4a", "mp3", "mpc", "flac")}

		TestTrack.tracks = {ext: Track(filename, TestTrack.modified, True) for ext, filename in TestTrack.files.iteritems()}

		TestTrack.artist = "Testy McTesterson"

		TestTrack.album = "Test Test Test"

		TestTrack.flags = ['Favorite','Christmas','Halloween','Patriotic','Valentine']

		TestTrack.titles = {
			"ogg": "OGG Test",
			"m4a": "M4A/MP4 Test",
			"mp3": "MP3 Test",
			"mpc": "MPC Test",
			"flac": "FLAC Test"
		}

		TestTrack.lengths = {
			"ogg":  1.3483446712018141,
			"m4a":  1.3003174603174603,
			"mp3":  1.4479479273723879,
			"mpc":  1.3453061224489795,
			"flac":  1.3483446712018141
		}

	def test_ogg_artist(self):
		self.assertEqual(TestTrack.tracks["ogg"].artist, TestTrack.artist)

	def test_ogg_album(self):
		self.assertEqual(TestTrack.tracks["ogg"].album, TestTrack.album)

	def test_ogg_flags(self):
		self.assertEqual(TestTrack.tracks["ogg"].flags, TestTrack.flags)

	def test_ogg_title(self):
		self.assertEqual(TestTrack.tracks["ogg"].title, TestTrack.titles["ogg"])

	def test_ogg_length(self):
		self.assertEqual(TestTrack.tracks["ogg"].length, TestTrack.lengths["ogg"])

	def test_ogg_filename(self):
		self.assertEqual(TestTrack.tracks["ogg"].filename, TestTrack.files["ogg"])

	def test_ogg_repr(self):
		self.assertEqual(repr(TestTrack.tracks["ogg"]), TestTrack.files["ogg"])

	def test_ogg_str(self):
		self.assertEqual(str(TestTrack.tracks["ogg"]), settings.data.track_format.format(**TestTrack.tracks["ogg"].__dict__))

	def test_ogg_modified(self):
		self.assertEqual(TestTrack.tracks["ogg"].modified, TestTrack.modified)

	def test_ogg_hash(self):
		self.assertEqual(TestTrack.tracks["ogg"].__hash__(), TestTrack.files["ogg"].__hash__())

	def test_ogg_not_equal(self):
		self.assertNotEqual(TestTrack.tracks["ogg"], TestTrack.files["ogg"][:-1])

	def test_ogg_greater(self):
		self.assertGreater(TestTrack.tracks["ogg"], TestTrack.files["ogg"][:-1])

	def test_ogg_lesser(self):
		self.assertLess(TestTrack.tracks["ogg"], TestTrack.files["ogg"] + "a")

	def test_ogg_greater_equal(self):
		self.assertGreaterEqual(TestTrack.tracks["ogg"], TestTrack.files["ogg"][:-1])
		self.assertGreaterEqual(TestTrack.tracks["ogg"], TestTrack.files["ogg"])

	def test_ogg_lesser_equal(self):
		self.assertLessEqual(TestTrack.tracks["ogg"], TestTrack.files["ogg"] + "a")
		self.assertLessEqual(TestTrack.tracks["ogg"], TestTrack.files["ogg"])


	def test_m4a_artist(self):
		self.assertEqual(TestTrack.tracks["m4a"].artist, TestTrack.artist)

	def test_m4a_album(self):
		self.assertEqual(TestTrack.tracks["m4a"].album, TestTrack.album)

	def test_m4a_flags(self):
		self.assertEqual(TestTrack.tracks["m4a"].flags, TestTrack.flags)

	def test_m4a_title(self):
		self.assertEqual(TestTrack.tracks["m4a"].title, TestTrack.titles["m4a"])

	def test_m4a_length(self):
		self.assertEqual(TestTrack.tracks["m4a"].length, TestTrack.lengths["m4a"])

	def test_m4a_filename(self):
		self.assertEqual(TestTrack.tracks["m4a"].filename, TestTrack.files["m4a"])

	def test_m4a_repr(self):
		self.assertEqual(repr(TestTrack.tracks["m4a"]), TestTrack.files["m4a"])

	def test_m4a_str(self):
		self.assertEqual(str(TestTrack.tracks["m4a"]), settings.data.track_format.format(**TestTrack.tracks["m4a"].__dict__))

	def test_m4a_modified(self):
		self.assertEqual(TestTrack.tracks["m4a"].modified, TestTrack.modified)

	def test_m4a_hash(self):
		self.assertEqual(TestTrack.tracks["m4a"].__hash__(), TestTrack.files["m4a"].__hash__())

	def test_m4a_not_equal(self):
		self.assertNotEqual(TestTrack.tracks["m4a"], TestTrack.files["m4a"][:-1])

	def test_m4a_greater(self):
		self.assertGreater(TestTrack.tracks["m4a"], TestTrack.files["m4a"][:-1])

	def test_m4a_lesser(self):
		self.assertLess(TestTrack.tracks["m4a"], TestTrack.files["m4a"] + "a")

	def test_m4a_greater_equal(self):
		self.assertGreaterEqual(TestTrack.tracks["m4a"], TestTrack.files["m4a"][:-1])
		self.assertGreaterEqual(TestTrack.tracks["m4a"], TestTrack.files["m4a"])

	def test_m4a_lesser_equal(self):
		self.assertLessEqual(TestTrack.tracks["m4a"], TestTrack.files["m4a"] + "a")
		self.assertLessEqual(TestTrack.tracks["m4a"], TestTrack.files["m4a"])


	def test_mp3_artist(self):
		self.assertEqual(TestTrack.tracks["mp3"].artist, TestTrack.artist)

	def test_mp3_album(self):
		self.assertEqual(TestTrack.tracks["mp3"].album, TestTrack.album)

	def test_mp3_flags(self):
		self.assertEqual(TestTrack.tracks["mp3"].flags, TestTrack.flags)

	def test_mp3_title(self):
		self.assertEqual(TestTrack.tracks["mp3"].title, TestTrack.titles["mp3"])

	def test_mp3_length(self):
		self.assertEqual(TestTrack.tracks["mp3"].length, TestTrack.lengths["mp3"])

	def test_mp3_filename(self):
		self.assertEqual(TestTrack.tracks["mp3"].filename, TestTrack.files["mp3"])

	def test_mp3_repr(self):
		self.assertEqual(repr(TestTrack.tracks["mp3"]), TestTrack.files["mp3"])

	def test_mp3_str(self):
		self.assertEqual(str(TestTrack.tracks["mp3"]), settings.data.track_format.format(**TestTrack.tracks["mp3"].__dict__))

	def test_mp3_modified(self):
		self.assertEqual(TestTrack.tracks["mp3"].modified, TestTrack.modified)

	def test_mp3_hash(self):
		self.assertEqual(TestTrack.tracks["mp3"].__hash__(), TestTrack.files["mp3"].__hash__())

	def test_mp3_not_equal(self):
		self.assertNotEqual(TestTrack.tracks["mp3"], TestTrack.files["mp3"][:-1])

	def test_mp3_greater(self):
		self.assertGreater(TestTrack.tracks["mp3"], TestTrack.files["mp3"][:-1])

	def test_mp3_lesser(self):
		self.assertLess(TestTrack.tracks["mp3"], TestTrack.files["mp3"] + "a")

	def test_mp3_greater_equal(self):
		self.assertGreaterEqual(TestTrack.tracks["mp3"], TestTrack.files["mp3"][:-1])
		self.assertGreaterEqual(TestTrack.tracks["mp3"], TestTrack.files["mp3"])

	def test_mp3_lesser_equal(self):
		self.assertLessEqual(TestTrack.tracks["mp3"], TestTrack.files["mp3"] + "a")
		self.assertLessEqual(TestTrack.tracks["mp3"], TestTrack.files["mp3"])


	def test_mpc_artist(self):
		self.assertEqual(TestTrack.tracks["mpc"].artist, TestTrack.artist)

	def test_mpc_album(self):
		self.assertEqual(TestTrack.tracks["mpc"].album, TestTrack.album)

	def test_mpc_flags(self):
		self.assertEqual(TestTrack.tracks["mpc"].flags, TestTrack.flags)

	def test_mpc_title(self):
		self.assertEqual(TestTrack.tracks["mpc"].title, TestTrack.titles["mpc"])

	def test_mpc_length(self):
		self.assertEqual(TestTrack.tracks["mpc"].length, TestTrack.lengths["mpc"])

	def test_mpc_filename(self):
		self.assertEqual(TestTrack.tracks["mpc"].filename, TestTrack.files["mpc"])

	def test_mpc_repr(self):
		self.assertEqual(repr(TestTrack.tracks["mpc"]), TestTrack.files["mpc"])

	def test_mpc_str(self):
		self.assertEqual(str(TestTrack.tracks["mpc"]), settings.data.track_format.format(**TestTrack.tracks["mpc"].__dict__))

	def test_mpc_modified(self):
		self.assertEqual(TestTrack.tracks["mpc"].modified, TestTrack.modified)

	def test_mpc_hash(self):
		self.assertEqual(TestTrack.tracks["mpc"].__hash__(), TestTrack.files["mpc"].__hash__())

	def test_mpc_not_equal(self):
		self.assertNotEqual(TestTrack.tracks["mpc"], TestTrack.files["mpc"][:-1])

	def test_mpc_greater(self):
		self.assertGreater(TestTrack.tracks["mpc"], TestTrack.files["mpc"][:-1])

	def test_mpc_lesser(self):
		self.assertLess(TestTrack.tracks["mpc"], TestTrack.files["mpc"] + "a")

	def test_mpc_greater_equal(self):
		self.assertGreaterEqual(TestTrack.tracks["mpc"], TestTrack.files["mpc"][:-1])
		self.assertGreaterEqual(TestTrack.tracks["mpc"], TestTrack.files["mpc"])

	def test_mpc_lesser_equal(self):
		self.assertLessEqual(TestTrack.tracks["mpc"], TestTrack.files["mpc"] + "a")
		self.assertLessEqual(TestTrack.tracks["mpc"], TestTrack.files["mpc"])


	def test_flac_artist(self):
		self.assertEqual(TestTrack.tracks["flac"].artist, TestTrack.artist)

	def test_flac_album(self):
		self.assertEqual(TestTrack.tracks["flac"].album, TestTrack.album)

	def test_flac_flags(self):
		self.assertEqual(TestTrack.tracks["flac"].flags, TestTrack.flags)

	def test_flac_title(self):
		self.assertEqual(TestTrack.tracks["flac"].title, TestTrack.titles["flac"])

	def test_flac_length(self):
		self.assertEqual(TestTrack.tracks["flac"].length, TestTrack.lengths["flac"])

	def test_flac_filename(self):
		self.assertEqual(TestTrack.tracks["flac"].filename, TestTrack.files["flac"])

	def test_flac_repr(self):
		self.assertEqual(repr(TestTrack.tracks["flac"]), TestTrack.files["flac"])

	def test_flac_str(self):
		self.assertEqual(str(TestTrack.tracks["flac"]), settings.data.track_format.format(**TestTrack.tracks["flac"].__dict__))

	def test_flac_modified(self):
		self.assertEqual(TestTrack.tracks["flac"].modified, TestTrack.modified)

	def test_flac_hash(self):
		self.assertEqual(TestTrack.tracks["flac"].__hash__(), TestTrack.files["flac"].__hash__())

	def test_flac_not_equal(self):
		self.assertNotEqual(TestTrack.tracks["flac"], TestTrack.files["flac"][:-1])

	def test_flac_greater(self):
		self.assertGreater(TestTrack.tracks["flac"], TestTrack.files["flac"][:-1])

	def test_flac_lesser(self):
		self.assertLess(TestTrack.tracks["flac"], TestTrack.files["flac"] + "a")

	def test_flac_greater_equal(self):
		self.assertGreaterEqual(TestTrack.tracks["flac"], TestTrack.files["flac"][:-1])
		self.assertGreaterEqual(TestTrack.tracks["flac"], TestTrack.files["flac"])

	def test_flac_lesser_equal(self):
		self.assertLessEqual(TestTrack.tracks["flac"], TestTrack.files["flac"] + "a")
		self.assertLessEqual(TestTrack.tracks["flac"], TestTrack.files["flac"])


if __name__ == '__main__':
	unittest.main()

